from base.base import Base
from selenium.webdriver.common.by import By
class PageCard(Base):
    # Iframe
    card_iframe = By.CSS_SELECTOR, "#layui-layer-iframe1"
    # 添加成功提示对象
    cart_iframe_add_result = By.CSS_SELECTOR, ".conect-title>span"
    # 关闭提示窗口
    cart_iframe_close_window = By.CSS_SELECTOR, ".layui-layer-close"

    # 全选
    checkbox_all = By.CSS_SELECTOR, ".cart-checkbox .check-box"
    # 去结算
    settlement_btn = By.CSS_SELECTOR, ".paytotal"


    # 获取添加结果
    def get_iframe_text(self):
        # 切换frame表单 以name属性切换 由于电脑配置问题，导致加载比较慢 不建议使用；
        # self.base_switch_frame(page.cart_frame_name)
        # 以元素切换 推荐
        self.base_switch_frame(self.base_find(self.card_iframe))
        # 获取结果并返回
        return self.base_get_text(self.cart_iframe_add_result)

    # 关闭窗口
    def close_iframe_window(self):
        # 回到默认目录
        self.base_default_content()
        # 点击关闭操作
        self.base_click(self.cart_iframe_close_window)

    # 点击全选
    def click_all_select(self):
        # 判断 如果没选中 就进行点击操作
        if not self.base_find(self.checkbox_all).is_selected():
            self.base_click(self.checkbox_all)
    # 点击去结算
    def click_settlement_btn(self):
        self.base_click(self.settlement_btn)
